package com.ruyuan2020.im.design.mementopattern.use;

import java.util.Stack;

/**
 *  Caretaker.java - 管理者类，负责保存备忘录对象，但不了解其内容
 */
public class Caretaker {
    private final Stack<Memento> savedStates = new Stack<>();

    public void addMemento(Memento memento) {
        savedStates.push(memento);
    }

    public Memento getMemento() {
        return savedStates.pop();
    }

    // 检查是否有保存的状态可供恢复
    public boolean hasSavedStates() {
        return !savedStates.isEmpty();
    }
}
